package com.syh.jn.scm.service.impl.operation.system;

import cn.redscarf.commons.wrapper.Restrictions;
import cn.redscarf.commons.wrapper.Wrapper;
import com.alibaba.dubbo.config.annotation.Service;
import com.syh.jn.scm.domain.operation.entity.system.TerminalAccountOfPhone;
import com.syh.jn.scm.domain.operation.repository.system.TerminalAccountOfPhoneReadRepository;
import com.syh.jn.scm.domain.operation.repository.system.TerminalAccountOfPhoneRepository;
import com.syh.jn.scm.dto.operation.system.TerminaAccountOfPhone.TerminalAccountOfPhoneVo;
import com.syh.jn.scm.dto.operation.system.TerminaAccountOfPhone.TerminalAccountVo;
import com.syh.jn.scm.service.api.operation.system.TerminalAccountOfPhoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by soci.song on 2018/12/13.
 */
@Service
@Transactional
public class TerminalAccountOfPhoneServiceImpl implements TerminalAccountOfPhoneService {

  @Autowired
  private TerminalAccountOfPhoneRepository repository;
  @Resource(name = "terminalAccountOfPhoneReadRepositoryImpl")
  private TerminalAccountOfPhoneReadRepository readRepository;


  @Override
  public void delete(Long id) {
    TerminalAccountOfPhone entity = repository.getById(id);
    entity.destory();
    repository.remove(entity);
  }

  @Override
  public TerminalAccountOfPhoneVo getById(Long id) {
    return readRepository.getById(id);
  }

  @Override
  public boolean contains(Long id) {
    return readRepository.getById(id) != null;
  }

  @Override
  public List<TerminalAccountOfPhoneVo> findList(Wrapper wrapper) {
    return this.findListPage(wrapper, null, null);
  }

  @Override
  public List<TerminalAccountOfPhoneVo> findListPage(Wrapper wrapper, Integer startRow, Integer count) {
    return readRepository.findListPage(wrapper, startRow, count);
  }

  @Override
  public TerminalAccountOfPhoneVo getOne(Wrapper wrapper) {
    return readRepository.getOne(wrapper);
  }

  @Override
  public int getCount(Wrapper wrapper) {
    return readRepository.getCount(wrapper);
  }

  @Override
  public void binding(Long id, Long accountId) {
    TerminalAccountOfPhone entity = repository.getById(id);
    entity.binding(accountId);
    repository.update(entity);
  }

  @Override
  public void untying(Long id, Long accountId) {
    TerminalAccountOfPhone entity = repository.getById(id);
    entity.untying(accountId);
    repository.update(entity);
  }

  @Override
  public void enable(Long id) {
    TerminalAccountOfPhone entity = repository.getById(id);
    entity.enable();
    repository.update(entity);
  }

  @Override
  public void disable(Long id) {
    TerminalAccountOfPhone entity = repository.getById(id);
    entity.disable();
    repository.update(entity);
  }

  @Override
  public List<TerminalAccountVo> getAccounts(Wrapper wrapper) {
    List<TerminalAccountVo> accountVos = readRepository.getAccountVoList(wrapper);
    return accountVos;
  }

  @Override
  public List<TerminalAccountVo> findAccountListPage(Wrapper wrapper, int startRow, int pageCount) {
    return this.readRepository.findAccountListPage(wrapper, startRow, pageCount);
  }

  @Override
  public int getAccountCount(Wrapper wrapper) {
    return this.readRepository.getAccountCount(wrapper);
  }
}
